import { _decorator, Component, JsonAsset, Node, resources } from 'cc';
import { SGame } from '../../sgame/SGame';
import { llog } from '../../sgame/logger/Logger';
import { config_del, config_get, config_set } from '../../sgame/config/Config';
const { ccclass, property } = _decorator;

@ccclass('Main')
export class Main extends Component {
    async start() {
        const config: object = await (new Promise((resolve, reject) => {
            resources.load("config/config", function (err, jsonObj: JsonAsset) {
                if (err) {
                    console.error(err);
                    reject(err);
                } else {
                    resolve(jsonObj.json);
                }
            });
        }));

        SGame.Init(config);
        llog("logger", config_get("logger"));
        llog("logger.enable", config_get("logger.enable"));

        llog("set a.b.c");
        config_set("a.b.c", 1);
        llog("a", config_get("a"));
        llog("a.b.c", config_get("a.b.c"));

        llog("delete logger");
        config_del("logger");
        llog("logger", config_get("logger"));
    }
}